
import java.util.Arrays;

public class Test12 {

    //打印1到最大的n位数的主方法
    public static void printToMaxOfDigits(int n){
        if(n <= 0) throw new RuntimeException("invalid");
        char[] nums = new char[n];
        Arrays.fill(nums,'0');
        for(int i = 0;i<10;i++){
            nums[0] = (char)(i+'0');
            printToMaxOfNDigitsRecursively(nums,n,0);
        }

    }
    //利用递归实现1到最大的n位数的全排列
    public static void printToMaxOfNDigitsRecursively(char[] number, int n, int index) {
        if(index == n-1){//排列结束
            printNumber(number);
            return;
        }
        for(int i = 0; i<10;i++){
            number[index+1] = (char)(i+'0');
            printToMaxOfNDigitsRecursively(number,n,index+1);
        }
    }

    //输出
    private  static void printNumber(char[] number) {
        boolean flag = true;
        for(int i =0;i<number.length;i++){
            if(flag && number[i] != '0'){
                flag = false;
            }
            if(!flag) System.out.print(number[i]);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        printToMaxOfDigits(2);
    }
}
